package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Banner;
import cn.wolfcode.wolf2w.query.QueryObject;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IBannerService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("banner")
@Controller
public class BannerController {
    @Autowired
    private IBannerService bannerService;
    @Autowired
    private IDestinationService destinationService;

    @RequestMapping("list")
    public String list(Model model,@ModelAttribute("qo") QueryObject qo){
        Page<Banner> page = bannerService.queryPageList(qo);
        model.addAttribute("page",page);
        return "banner/list";
    }



    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Banner banner){
        if(StringUtils.hasLength(banner.getId())){
            bannerService.update(banner);
        }else{
            bannerService.save(banner);
        }
        return JsonResult.success();
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(String id){
        bannerService.delete(id);
        return JsonResult.success();
    }


    @RequestMapping("getAllType")
    @ResponseBody
    public Object getAllType(){
        Map map = bannerService.getAllType();
        return JsonResult.success(map);
    }
}
